<template>
  <div>

    <!-- 阿里云视频播放器样式 -->
    <link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.8.1/skins/default/aliplayer-min.css" />
    <!-- 阿里云视频播放器脚本 -->
    <script charset="utf-8" type="text/javascript" src="https://g.alicdn.com/de/prismplayer/2.8.1/aliplayer-min.js" />
    <div class="aa">
      <!-- 定义播放器dom -->
      <div id="J_prismPlayer" class="prism-player" />
    </div>
  </div>
</template>
<script>
  import vod from '../../api/vod'
  export default {
    asyncData({params,error}){
      //params.id：获取路由中的ID
      return vod.getPlayAuth(params.vid).then(respone=>{
        return {
          playAuth: respone.data.data.playAuth,
          vid: params.vid
        }
      }).catch(()=>{
        // this.$message.error('erroe')
      })
    },
    //在页面渲染之后调用
    mounted(){
      new Aliplayer({
        id: 'J_prismPlayer',
        autoplay: false,
        vid: this.vid, // 视频id
        playauth: this.playAuth, // 播放凭证
        encryptType: '1', // 如果播放加密视频，则需设置encryptType=1，非加密视频无需设置此项
        width: '100%',
        height: '600px',
        controlBarVisibility: 'hover', // 控制条的显示方式：鼠标悬停
        useH5Prism: true, // 播放器类型：html5
      }, function(player) {
        console.log('播放器创建成功')
      })
    }
  }
</script>
<style>
  .aa{
    margin: 0px auto;
  }
</style>
